package com.example.jh352160.surfingtv.mypage.childPage;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.example.jh352160.surfingtv.R;
import com.example.jh352160.surfingtv.guid.GuidActivity;
import com.example.jh352160.surfingtv.mypage.customView.MypageItem;
import com.example.jh352160.surfingtv.network.item.RequestItem;
import com.example.jh352160.surfingtv.network.retrofit.CommonRetrofit;
import com.example.jh352160.surfingtv.network.service.MyDataService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by jh352160 on 2016/7/26
 */

public class MypageSetting extends AppCompatActivity implements View.OnClickListener {

    MypageItem item1, item2;
    Toolbar toolbar;
    TextView logout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mypage_setting);
        item1 = (MypageItem) findViewById(R.id.mypageItem1);
        item2 = (MypageItem) findViewById(R.id.mypageItem2);
        logout = (TextView) findViewById(R.id.logout);
        item1.setView("绑定手机号");
        item2.setView("修改密码");
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
        logout.setOnClickListener(this);
        item1.setOnClickListener(this);
        item2.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.mypageItem1:
                intent = new Intent(this, BindTelephone.class);
                startActivity(intent);
                break;
            case R.id.mypageItem2:
                intent = new Intent(this, ChangePassword.class);
                startActivity(intent);
                break;
            case R.id.logout:
                Retrofit retrofit = CommonRetrofit.getRetrofit();
                MyDataService myDataService = retrofit.create(MyDataService.class);
                Call<RequestItem> call = myDataService.logout();
                call.enqueue(new Callback<RequestItem>() {
                    @Override
                    public void onResponse(Call<RequestItem> call, Response<RequestItem> response) {
                        GuidActivity.page = 1;
                        GuidActivity.isLogin = false;
                        MypageSetting.this.finish();
                    }

                    @Override
                    public void onFailure(Call<RequestItem> call, Throwable t) {

                    }
                });
                break;
        }
    }
}
